import requests
from concurrent.futures import ThreadPoolExecutor

# 接口 URL 模板
url_template = "http://106.52.201.90:7001/api/ccSmartStrategy/genTopic/invoke?spanId={}"

# 不同的 spanId 列表
span_ids = [
"xf1a8li1avvnk",
"xf1a8n13kt24g"
]

# 请求头
headers = {
    'User-Agent': 'Apifox/1.0.0 (https://apifox.com)'
}

# 定义请求函数
def call_api(span_id):
    url = url_template.format(span_id)
    try:
        requests.get(url, headers=headers, timeout=1)  # 设置 timeout 避免阻塞
        print(f"Request sent with spanId={span_id}")
    except Exception as e:
        print(f"Error with spanId={span_id}: {e}")

# 使用线程池异步调用
with ThreadPoolExecutor(max_workers=10) as executor:  # 最多 10 个并发
    executor.map(call_api, span_ids)

print("All requests sent asynchronously!")